<template>
  <!-- 查看详情 2018/3/7 11:44 zhangQ -->
  <div>

    <tablePage ref="subOrderTab" :staticData="subOrderData" :isStartLoad="false" :mode="1">
      <template slot-scope="props">
        <Table :columns="subOrderColumn" border :data="props.data" @on-sort-change="props.sortChange"></Table>
      </template>
    </tablePage>
  </div>
</template>

<script>
  import {getFleetOrderByMainOrderNo} from '@api/backEnd/mainOrder'
  import xlinkModal from '@components/modal/xlinkModal'
  import viewMedia from './viewMedia'
  import tablePage from '@components/table/tablePage.vue'
  import moment from 'moment'

  export default {
    name: 'view-fleet',
    data () {
      let subOrderColumn = [
        {
          title: '派单人',
          ellipsis: 'true',
          key: 'dispatchOrgName',
          width: 200
        },
        {
          title: '车队',
          ellipsis: 'true',
          key: 'orgName',
          width: 200
        },
        {
          title: '创建时间',
          ellipsis: 'true',
          width: 200,
          key: 'createTime',
          render: (h, params) => {
            let thisdata = params.row.createTime
            thisdata = thisdata ? moment(thisdata).format('YYYY-MM-DD HH:mm') : ''
            return (<span>{thisdata}</span>)
          }
        }
      ]
      let subOrderData = []
      let datas = {subOrderColumn, subOrderData}
      return datas
    },
    props: {
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      /**
       * TODO(获得子运单信息)
       * @auther zhangQ
       * @date 2018/3/16 15:40
       **/
      getSubOrderData () {
        if (!(this.currentMainOrder && this.currentMainOrder.orderNo)) {
          return
        }
        let param = {
          mainOrderNo: this.currentMainOrder.orderNo
        }
        getFleetOrderByMainOrderNo(param).then(res => {
          console.log(res)
          if (res.data.isSuccess === 1) {
            this.subOrderData = res.data.data.rows
          } else {
            Promise.reject(new Error(res.data.res))
          }
        }).catch((err) => {
          console.log('接口getOrderDetail:' + err)
        })
      }
    },
    watch: {
      subOrderTabParam: {
        handler: function (val, oldVal) {
          this.getSubOrderData()
        },
        deep: true
      }
    },
    mounted () {
      this.getSubOrderData()
    },
    components: {tablePage, xlinkModal, viewMedia}
  }
</script>
